<template>
  <div class="home">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#d3dce6"
          text-color="#000"
          active-text-color="#1a73e8"
          unique-opened
        >
          <div class="logo">
            <img src="../../public/logo.png" class="logoimg" />
            <span class="span">盛邦升华</span>
          </div>
          <el-menu-item
            v-for="(item, index) of navList"
            :key="index"
            :index="item.path"
            @click="
              () => {
                $router.push(item.path).catch((err) => err);
              }
            "
          >
            <template slot="title">
              <!-- <i :class="item.icon"></i> -->
              {{ item.meta.title }}
            </template>
            <!-- <el-menu-item-group
              v-for="childItem of item.child"
              :key="childItem.index"
            >
              <el-menu-item
                @click="handleClickItem(childItem.src, childItem.title)"
                :index="childItem.index"
                >{{ childItem.title }}</el-menu-item
              >
            </el-menu-item-group> -->
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <p></p>
          <span>考试管理系统 </span>
          <div class="avatar">
            <el-dropdown :hide-on-click="false">
              <span class="el-dropdown-link">
                <el-avatar
                  src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
                ></el-avatar>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <span @click="replace">更换头像</span>
                </el-dropdown-item>
                <el-dropdown-item @click="mycard">我的资料</el-dropdown-item>
                <router-link to="/user/editpass">
                  <el-dropdown-item>修改密码</el-dropdown-item>
                </router-link>
                <el-dropdown-item
                  ><span @click="logout">退出登录</span></el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <el-tag
            v-for="(tag, index) in tags"
            :key="index"
            closable
            @close="handleCloseTag(index)"
            @click="navChange(tag.url)"
            >{{ tag.name }}</el-tag
          >
          <!-- <keep-alive> -->

          <transition  name="slide-left" mode="out-in">
            <router-view :key="$route.fullPath"></router-view>
          </transition>
          <!-- </keep-alive> -->
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import navLists from "@/data/home_nav";
export default {
  data() {
    return {
      list: navLists,
      tags: [],
    };
  },
  computed: {
    // 菜单列表
    navList: function () {
      return this.$router.options.routes[0].children.filter(
        (item) => item.meta.isNav != false
      );
      // return console.log(this)
    },
  },
  methods: {
    // 点击修改密码
    editpass() {},
    // 点击更换头像
    replace() {
      this.$router.push("/user/upload");
    },
    // 点击进入我的资料
    mycard() {
      // this.$router.push("/personal")
    },
    // 点击删除悬浮导航
    handleCloseTag(e) {
      this.tags.splice(e, 1);
    },
    // 点击悬浮导航跳转
    navChange(url) {
      this.$router.push(url).catch((err) => err);
    },
    // 点击导航菜单跳转
    handleClickItem(url, e) {
      try {
        let re = this.tags.find((item) => {
          return e === item.name;
        });
        if (!re) {
          this.tags.push({ name: e, url });
        }
        this.$router.push(url).catch((err) => err);
        console.log(url);
      } catch (e) {
        console.log(e);
      }
    },
    handleOpen() {
      // console.log(key, keyPath);
    },
    handleClose() {
      // console.log(key, keyPath);
    },
    // 登出
    logout() {
      console.log("asdfa");
      window.sessionStorage.clear();
      location.reload();
    },
  },
};
</script>
<style lang="less">
.slide-left-enter {
    opacity: 0;
    -webkit-transform: translate(100px, 0px);
    transform: translate(-100px,0px);
  }
  .slide-left-enter-active{
    transition: all 0.3s linear;
  }
  .slide-left-leave-to{
    opacity: 0;
    -webkit-transform: translate(-100px,0px );
    transform: translate( 100px,0px);
  }
  .slide-left-leave-active {
    transition: all 0.3s linear;
  }



.home {
  width: 100%;
  height: 100%;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .avatar {
    width: 66px;
    height: 40px;
    position: relative;
    .el-dropdown-link {
      cursor: pointer;
    }
    .el-icon-arrow-down {
      font-size: 15px;
    }
    .dropdown {
      margin-top: -20px;
    }
  }
}
.el-dropdown {
  height: 40px;
}
.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
  position: relative;
  .el-menu {
    // margin-top: 60px;
    border: none;
  }
  .logo {
    width: 100%;
    height: 60px;
    position: relative;
    .logoimg {
      width: 40px;
      position: absolute;
      top: 12px;
      left: 13px;
    }
    .span {
      position: absolute;
      top: 22px;
      left: 60px;
      line-height: 20px;
      font-size: 20px;
      font-weight: bolder;
      color: #18469c;
    }
  }
}

.el-main {
  background-color: #fff;
  color: #333;
  overflow: hidden;
}

.el-container {
  height: 100%;
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-submenu .el-submenu__title {
  padding: 0 50px;
}
.el-submenu__title .el-submenu__icon-arrow {
  right: 50px;
  margin-top: -7px;
  transition: transform 0.3s;
  font-size: 15px;
}
.el-tag {
  margin-left: 10px;
  margin-bottom: 15px;
  cursor: pointer;
}
</style>
